import pymongo


class Mongodb:
    "mongodb 操作"

    def connect(self, db_name, collection_name):
        "创建数据库连接,返回一个集合"
        self.connection = pymongo.MongoClient('127.0.0.1', 27017)
        db = self.connection[db_name]
        return db[collection_name]

    def insert(self, data):
        self.connection.insert(data)

    def find(self):
        info = self.connection.find()
        return info

    def find_one(self, condition):
        return self.collection.find_one(condition)

    def remove(self, item):
        self.connection.remove(item)
